<?php

namespace app\admin\controller;

use app\common\model\ShopMemberMonths;
use app\common\model\ShopMemberMonthsRecord;
use buildView\Button;
use buildView\Filter;
use think\Controller;
use buildView\Grid;

/**
 * 每月免费次数记录
 * Class MemberMonths
 * @package app\admin\controller
 */
class MemberMonths extends Controller
{
    /**
     * 列表
     * @auth true
     * @menu true
     * @return string
     */
    public function index()
    {
        $grid = new Grid(new ShopMemberMonths);
        $grid->month('月份');
        $grid->num('发放次数');
        $grid->create_at('发放时间');
        $grid->hideAddButton();
        $grid->hideExportButton();
        $grid->hideDeletesButton();
        $grid->filter(function(Filter $filter){
            $filter->dateBetween('create_at','发放时间');
        });
        $grid->actions(function($action,$data){
            $button = new Button('发放记录','warm');
            $button->href(url('record') ."?cid={$data['id']}");
            $action->prepend($button);
            $action->hideDel();
            $action->hideDetail();
            $action->hideEdit();
        });
        return $grid->view();
    }

    /**
     * 领取记录
     * @auth true
     * @menu true
     * @return string
     */
    public function record()
    {
        $cid = $this->request->get('cid');
        $grid = new Grid(new ShopMemberMonthsRecord);
        $grid->model()->where('month_id', $cid);
        $grid->user()->userInfo();
        $grid->column('create_at','发放时间');
        $grid->filter(function ($filter){
            $filter->dateBetween('create_at','发放时间');
        });
        $grid->hideAction();
        $grid->hideAddButton();
        $grid->hideExportButton();
        $grid->hideExportButton();
        $grid->actions(function ($action){
        });
        return $grid->view();
    }
}
